package day0401;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class KaoQingInfo10 {
    /**
     * 10.【考勤信息】
     * 公司用一个字符串来表示员工的出勤信息
     * <p>
     * absent：缺勤
     * late：迟到
     * leaveearly：早退
     * present：正常上班
     * 现需根据员工出勤信息，判断本次是否能获得出勤奖，能获得出勤奖的条件如下：
     * <p>
     * 缺勤不超过一次；
     * 没有连续的迟到/早退；
     * 任意连续7次考勤，缺勤/迟到/早退不超过3次。
     * 如：
     * <p>
     * 2
     * present
     * present absent present present leaveearly present absent
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<String> question2 = Stream.of("late", "leaveearly").collect(Collectors.toList());
        List<String> question3 = Stream.of("late", "leaveearly", "absent").collect(Collectors.toList());
        while (n > 0) {
            String[] strings = sc.nextLine().split(" ");
            int absentNum = 0;
            boolean flag = true;
            for (int i = 0; i < strings.length; i++) {
                // question1
                if ("absent".equals(strings[i])) {
                    absentNum++;
                }
                if (absentNum >= 2) {
                    flag = false;
                    break;
                }
                // question2
                if (i < strings.length - 1) {
                    if (question2.contains(strings[i]) && question2.contains(strings[i + 1])) {
                        flag = false;
                        break;
                    }
                }
            }

            // question3
            int start = 0;
            int end = Math.min(strings.length, 7);
            int count = 0;
            while (end <= strings.length) {
                for (int j = start; j < end; j++) {
                    if (question3.contains(strings[j])) {
                        count++;
                    }
                    if (count > 3) {
                        flag = false;
                        break;
                    }
                }
                count = 0;
                start++;
                end++;
            }
            System.out.println(flag);
            n--;
        }

    }
}
